<?php

namespace app\index\controller;

use think\exception\ValidateException;
use app\model\Points;

class PointsController extends Base
{
    //积分明细
    public function list()
    {
        $page = $this->request->param('page', 1);
        $pageSize = $this->request->param('pageSize', 20);
        $type = $this->request->param('type');
        $date_y = $this->request->param('date_y');
        $prefix = $this->request->param('prefix');
        $where['weid'] = weid();
        $where['uid'] = UID();
        if($type == 'jifen'){
            $where['from_type'] = 1;
        }elseif ($type == 'gx'){
            $where['from_type'] = 2;
        }
        if($prefix > 0){
            $where['prefix'] = $prefix;
        }
        $query = Points::where($where);
        if($date_y == 'today'){
            $query->where('create_time', 'between', "".strtotime(date('Y-m-d'))."," .strtotime(date('Y-m-d 23:59:59'))."");
        }
        $log = $query->limit(($page - 1) * $pageSize, $pageSize)->order('id desc')->select()->toArray();
//        echo (new Points())->getLastSql();exit();

        foreach ($log as &$vo) {
            if ($vo['type'] == 1) {
                $vo['typeStr'] = '下单';
            } elseif ($vo['type'] == 2) {
                $vo['typeStr'] = '管理员操作';
            }
        }
        $data = $log;
        return $this->json(['data' => $data]);
    }
}
